package com.rmt.www.action;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.rmt.www.dao.ArtifactDao;
import com.rmt.www.dao.ProjectDao;
import com.rmt.www.dao.RequestDao;
import com.rmt.www.dao.UserDao;
import com.rmt.www.service.SREManageFeatureService;
import com.rmt.www.service.SREManageRequirementService;
import com.rmt.www.utility.SystemTime;
import com.rmt.www.vo.Artifact;
import com.rmt.www.vo.FeatureArtifactRequest;
import com.rmt.www.vo.Project;
import com.rmt.www.vo.Request;
import com.rmt.www.vo.RequirementArtifactRequest;
import com.rmt.www.vo.User;


public class UpdateRequirementSubmitAction extends ActionSupport{
	private int pid;
	private int aid;
	private String title;
	private String version;
	private String priority;
	private String source;
	private String rational;
	private String status;
	private String cost;
	private String effort;
	private String risk;
	private String description;
	private RequestDao requestDao;
	private int authorId;
	private Timestamp createdtime;
	private int updatedtimes;
	private String requirementtype;
	private SREManageRequirementService SREManageRequirementService;

	public String getRequirementtype() {
		return requirementtype;
	}
	public void setRequirementtype(String requirementtype) {
		this.requirementtype = requirementtype;
	}
	public SREManageRequirementService getSREManageRequirementService() {
		return SREManageRequirementService;
	}
	public void setSREManageRequirementService(
			SREManageRequirementService sREManageRequirementService) {
		SREManageRequirementService = sREManageRequirementService;
	}

	public int getAuthorId() {
		return authorId;
	}
	public void setAuthorId(int authorId) {
		this.authorId = authorId;
	}
	public Timestamp getCreatedtime() {
		return createdtime;
	}
	public void setCreatedtime(Timestamp createdtime) {
		this.createdtime = createdtime;
	}
	public int getUpdatedtimes() {
		return updatedtimes;
	}
	public void setUpdatedtimes(int updatedtimes) {
		this.updatedtimes = updatedtimes;
	}

	public int getAid() {
		return aid;
	}
	public void setAid(int aid) {
		this.aid = aid;
	}
	
	public int getPid() {
		return pid;
	}
	public void setPid(int pid) {
		this.pid = pid;
	}
	public String getVersion() {
		return version;
	}
	public void setVersion(String version) {
		this.version = version;
	}
	public String getPriority() {
		return priority;
	}
	public void setPriority(String priority) {
		this.priority = priority;
	}
	public String getSource() {
		return source;
	}
	public void setSource(String source) {
		this.source = source;
	}
	public String getRational() {
		return rational;
	}
	public void setRational(String rational) {
		this.rational = rational;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getCost() {
		return cost;
	}
	public void setCost(String cost) {
		this.cost = cost;
	}
	public String getEffort() {
		return effort;
	}
	public void setEffort(String effort) {
		this.effort = effort;
	}
	public String getRisk() {
		return risk;
	}
	public void setRisk(String risk) {
		this.risk = risk;
	}
	public RequestDao getRequestDao() {
		return requestDao;
	}
	public void setRequestDao(RequestDao requestDao) {
		this.requestDao = requestDao;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	
	public String execute(){
		RequirementArtifactRequest r=new RequirementArtifactRequest();
		r.setPid(pid);
		r.setRequirementartifactid(aid);
		r.setTitle(title);
		r.setVersion(version);
		r.setPriority(priority);
		r.setSource(source);
		r.setRational(rational);
		r.setStatus(status);
		r.setDescription(description);
		r.setCost(cost);
		r.setEffort(Integer.parseInt(effort));
		r.setRisk(risk);
		r.setAuthorId(authorId);
		r.setCreatedtime(createdtime);
		r.setUpdatedtimes(updatedtimes);
		r.setRequirementtype(requirementtype);
		r.setRequesttype("update");
		User u=(User)ActionContext.getContext().getSession().get("currentUser");
		r.setUpdateUserId(u.getUid());

		//还要设置updatedtime为当前时间
		r.setUpdatedtime(new java.sql.Timestamp(SystemTime.getSystemTime().getTime()));
		
		SREManageRequirementService.updateRequirement(r);
		
		/*ActionContext ctx = ActionContext.getContext();        
		HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST); 
		request.setAttribute("pid", pid);*/
		
		return "success";
		
	}
}
